package com.zhengxin.controller;

import com.alibaba.fastjson.JSONObject;
import com.zhengxin.results.WebResult;
import com.zhengxin.service.LoginService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import static com.zhengxin.results.WebResult.REQUEST_STATUS_SUCCESS;

@RestController
@Api("登录/退出接口")
public class LoginController {

    @Autowired
    private LoginService loginService;

    @PostMapping("login")
    @ApiOperation("登录接口")
    public WebResult<String> login(@RequestBody JSONObject jsonObject) {
        System.out.println(jsonObject.getString("name") + " " + jsonObject.getString("password"));
        return WebResult.<String>builder()
                .code(200)
                .message(REQUEST_STATUS_SUCCESS)
                .data(loginService.login(jsonObject))
                .build();
    }

}
